package HashTable;

import java.util.HashMap;
import java.util.Map;

public class _771_JewelsandStones {
    public int numJewelsInStones(String J, String S) {
        Map<Character, Integer> map = new HashMap<>();
        int length = S.length();
        for(int i=0;i<length;i++) {
            Character s = S.charAt(i);
            if (map.containsKey(s)){
                map.put(s, map.get(s) + 1);
            }else {
                map.put(s, 1);
            }
        }
        int count = 0;
        int jlength = J.length();
        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
            for(int i=0;i<jlength;i++) {
                if (J.charAt(i) == entry.getKey()) {
                    count+=entry.getValue();
                    break;
                }
            }
        }
        return count;
    }

    public int numJewelsInStones1(String J, String S) {
        int count = 0;
        for (char c : S.toCharArray()) {
            if (J.indexOf(c) != -1) {
                count++;
            }
        }
        return count;
    }

}
